package com.fll.fangyiuser.service.impl;

import com.fll.fangyicommon.entity.user.Oss;
import com.fll.fangyiuser.dao.OssDao;
import com.fll.fangyiuser.service.OssService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author fll
 * @create 2023/2/24
 */
@Service
@Slf4j
public class OssServiceImpl implements OssService {

    @Autowired
    private OssDao ossDao;

    /**
     * 注册时插入oss
     * @param oss
     * @return
     */
    @Override
    public int insertOss(Oss oss){
        return ossDao.insertOss(oss);
    }

    /**
     * 根据ossId查询用户Oss
     * @param userId
     * @return
     */
    @Override
    public Oss selectOssByUserId(Integer userId) {
        Oss oss = ossDao.selectOssByUserId(userId);
        if (oss != null) {
            log.info("查询用户oss成功===>{}", oss);
            return oss;
        }
        log.error("查询用户oss失败===>{}", oss);
        return null;
    }


    /**
     * 根据userId更新背景图
     * @param userId
     * @param url
     * @return
     */
    @Override
    public Integer updateByUserId(Integer userId, String url) {
        Integer num = ossDao.updateByUserId(userId,url);
        if (num != 0) {
            log.info("背景图更新成功===>{},数据条===>{}", url,num);
            return num;
        }
        log.error("背景图更新失败===>{}, 数据条===>{}", url,num);
        return null;
    }

    /**
     * 根据userId更新头像
     * @param userId
     * @param url
     * @return
     */
    @Override
    public Integer updateAvatarByUserId(Integer userId, String url) {
        Integer num = ossDao.updateAvatarByUserId(userId,url);
        if (num != 0) {
            log.info("头像更新成功===>{},数据条===>{}", url,num);
            return num;
        }
        log.error("头像更新失败===>{}, 数据条===>{}", url,num);
        return null;
    }
}
